package com.pxmeta.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pxmeta.user.entity.Rank;
import com.pxmeta.user.entity.UserRank;
import com.pxmeta.user.entity.vo.RankVO;
import com.pxmeta.user.mapper.RankMapper;
import com.pxmeta.user.mapper.UserRankMapper;
import com.pxmeta.user.service.IRankService;
import com.pxmeta.user.service.IUserRankService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class RankServiceImpl extends ServiceImpl<RankMapper, Rank> implements IRankService {

    private static final Integer NOBLE_RANK_TYPE = 1;
    private static final Integer CHARM_RANK_TYPE = 2;

    @Override
    public Rank getNobleRank(Integer nobleRank) {
        LambdaQueryWrapper<Rank> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(Rank::getRankValue,nobleRank)
                .eq(Rank::getType, NOBLE_RANK_TYPE);

        return this.getOne(wrapper);
    }

    @Override
    public Rank getCharmRank(Integer charmRank) {
        LambdaQueryWrapper<Rank> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(Rank::getRankValue,charmRank)
                .eq(Rank::getType, CHARM_RANK_TYPE);

        return this.getOne(wrapper);
    }

    @Override
    public List<Rank> getRankList(Integer type) {
        LambdaQueryWrapper<Rank> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(Rank::getType, type)
                .orderByAsc(Rank::getRankValue);
        return this.list(wrapper);
    }
}
